module rf{
    export function map_create_data(id:string,pwc:number,phc:number){
        let data = {} as IMapData;
        data.id = id;
        data.pw = 256;
        data.ph = 256;

        data.w = pwc * data.pw;
        data.h = phc * data.ph;

        data.gew = 60;
        data.geh = 30;

        data.hgew = data.gew * 0.5;
        data.hgeh = data.geh * 0.5;

        data.gw = Math.floor(data.w / data.gew);
        data.gh = Math.floor(data.h / data.geh);


        data.w = data.gew * data.gw;// pwc * data.pw;
        data.h = data.geh * data.gh;


        let len = data.gw * data.gh;
        let buffer = new ArrayBuffer(len)
        let byte = new Byte(buffer);
        for(let i = 0;i<len;i++){
            byte.position = i;
            byte.writeByte(0o00000001);
        }

        data.byte = buffer;

        return data;

    }

    export interface IMapData{

        //格子宽度
        gw:number;
        //格子高度
        gh:number;

        //格子像素宽
        gew:number;
        //格子像素高
        geh:number;

        //格子一半像素宽
        hgew:number;
        //格子一半像素高
        hgeh:number;

        //像素宽度
        w:number;
        //像素高度
        h:number;

        //图片宽度
        pw:number;
        //图片高度
        ph:number;

        id:string;

        byte:ArrayBuffer;

        setting:Map2DSetting;

        // alpha:ArrayBuffer;
    }


    class MapGrap extends SceneObject{
        get available(){
            return true;
        }
    }

    export class SnakeMap extends SceneObject{

        static sourceSize = {x:2048,y:2048} as Point2D

        gx:number = -1;
        gy:number = -1;

        sw:number = 0;
        sh:number = 0;

        gw:number;
        gh:number;

        data:IMapData;

        perfix:string;

        mapHalo:Sprite;

        mapGrap:Sprite;

        // rtt:RTTexture;

        // snakes = [
        //     [0,0],[0,1],[-1,1],[-1,0],[-1,-1],[0,-1],[1,-1],[1,0],[1,1],[1,2],[0,2],[-1,2],[-2,2],[-2,1],[-2,0],[-2,-1],[-2,-2],[-1,-2],[0,-2],[1,-2],[2,-2],[2,-1],[2,0],[2,1],[2,2],[2,3],[1,3],[0,3],[-1,3],[-2,3],[-3,3],[-3,2],[-3,1],[-3,0],[-3,-1],[-3,-2],[-3,-3],[-2,-3],[-1,-3],[0,-3],[1,-3],[2,-3],[3,-3],[3,-2],[3,-1],[3,0],[3,1],[3,2],[3,3],[3,4],[2,4],[1,4],[0,4],[-1,4],[-2,4],[-3,4],[-4,4],[-4,3],[-4,2],[-4,1],[-4,0],[-4,-1],[-4,-2],[-4,-3],[-4,-4],[-3,-4],[-2,-4],[-1,-4],[0,-4],[1,-4],[2,-4],[3,-4],[4,-4],[4,-3],[4,-2],[4,-1],[4,0],[4,1],[4,2],[4,3],[4,4],[4,5],[3,5],[2,5],[1,5],[0,5],[-1,5],[-2,5],[-3,5],[-4,5],[-5,5],[-5,4],[-5,3],[-5,2],[-5,1],[-5,0],[-5,-1],[-5,-2],[-5,-3],[-5,-4],[-5,-5],[-4,-5],[-3,-5],[-2,-5],[-1,-5],[0,-5],[1,-5],[2,-5],[3,-5],[4,-5],[5,-5],[5,-4],[5,-3],[5,-2],[5,-1],[5,0],[5,1],[5,2],[5,3],[5,4],[5,5],[5,6],[4,6],[3,6],[2,6],[1,6],[0,6],[-1,6],[-2,6],[-3,6],[-4,6],[-5,6],[-6,6],[-6,5],[-6,4],[-6,3],[-6,2],[-6,1],[-6,0],[-6,-1],[-6,-2],[-6,-3],[-6,-4],[-6,-5],[-6,-6],[-5,-6],[-4,-6],[-3,-6],[-2,-6],[-1,-6],[0,-6],[1,-6],[2,-6],[3,-6],[4,-6],[5,-6],[6,-6],[6,-5],[6,-4],[6,-3],[6,-2],[6,-1],[6,0],[6,1],[6,2],[6,3],[6,4],[6,5],[6,6],[6,7],[5,7],[4,7],[3,7],[2,7],[1,7],[0,7],[-1,7],[-2,7],[-3,7],[-4,7],[-5,7],[-6,7],[-7,7],[-7,6],[-7,5],[-7,4],[-7,3],[-7,2],[-7,1],[-7,0],[-7,-1],[-7,-2],[-7,-3],[-7,-4],[-7,-5],[-7,-6],[-7,-7],[-6,-7],[-5,-7],[-4,-7],[-3,-7],[-2,-7],[-1,-7],[0,-7],[1,-7],[2,-7],[3,-7],[4,-7],[5,-7],[6,-7],[7,-7],[7,-6],[7,-5],[7,-4],[7,-3],[7,-2],[7,-1],[7,0],[7,1],[7,2],[7,3],[7,4],[7,5],[7,6],[7,7],[7,8],[6,8],[5,8],[4,8],[3,8],[2,8],[1,8],[0,8],[-1,8],[-2,8],[-3,8],[-4,8],[-5,8],[-6,8],[-7,8],[-8,8],[-8,7],[-8,6],[-8,5],[-8,4],[-8,3],[-8,2],[-8,1],[-8,0],[-8,-1],[-8,-2],[-8,-3],[-8,-4],[-8,-5],[-8,-6],[-8,-7],[-8,-8],[-7,-8],[-6,-8],[-5,-8],[-4,-8],[-3,-8],[-2,-8],[-1,-8],[0,-8],[1,-8],[2,-8],[3,-8],[4,-8],[5,-8],[6,-8],[7,-8],[8,-8],[8,-7],[8,-6],[8,-5],[8,-4],[8,-3],[8,-2],[8,-1],[8,0],[8,1],[8,2],[8,3],[8,4],[8,5],[8,6],[8,7],[8,8],[8,9],[7,9],[6,9],[5,9],[4,9],[3,9],[2,9],[1,9],[0,9],[-1,9],[-2,9],[-3,9],[-4,9],[-5,9],[-6,9],[-7,9],[-8,9],[-9,9],[-9,8],[-9,7],[-9,6],[-9,5],[-9,4],[-9,3],[-9,2],[-9,1],[-9,0],[-9,-1],[-9,-2],[-9,-3],[-9,-4],[-9,-5],[-9,-6],[-9,-7],[-9,-8],[-9,-9],[-8,-9],[-7,-9],[-6,-9],[-5,-9],[-4,-9],[-3,-9],[-2,-9],[-1,-9],[0,-9],[1,-9],[2,-9],[3,-9],[4,-9],[5,-9],[6,-9],[7,-9],[8,-9],[9,-9],[9,-8],[9,-7],[9,-6],[9,-5],[9,-4],[9,-3],[9,-2],[9,-1],[9,0],[9,1],[9,2],[9,3],[9,4],[9,5],[9,6],[9,7],[9,8],[9,9],[9,10],[8,10],[7,10],[6,10],[5,10],[4,10],[3,10],[2,10],[1,10],[0,10],[-1,10],[-2,10],[-3,10],[-4,10],[-5,10],[-6,10],[-7,10],[-8,10],[-9,10],[-10,10],[-10,9],[-10,8],[-10,7],[-10,6],[-10,5],[-10,4],[-10,3],[-10,2],[-10,1],[-10,0],[-10,-1],[-10,-2],[-10,-3],[-10,-4],[-10,-5],[-10,-6],[-10,-7],[-10,-8],[-10,-9],[-10,-10],[-9,-10],[-8,-10],[-7,-10],[-6,-10],[-5,-10],[-4,-10],[-3,-10],[-2,-10],[-1,-10],[0,-10],[1,-10],[2,-10],[3,-10],[4,-10],[5,-10],[6,-10],[7,-10],[8,-10],[9,-10],[10,-10],[10,-9],[10,-8],[10,-7],[10,-6],[10,-5],[10,-4],[10,-3],[10,-2],[10,-1],[10,0],[10,1],[10,2],[10,3],[10,4],[10,5],[10,6],[10,7],[10,8],[10,9],[10,10],[10,11],[9,11],[8,11],[7,11],[6,11],[5,11],[4,11],[3,11],[2,11],[1,11],[0,11],[-1,11],[-2,11],[-3,11],[-4,11],[-5,11],[-6,11],[-7,11],[-8,11],[-9,11],[-10,11],[-11,11],[-11,10],[-11,9],[-11,8],[-11,7],[-11,6],[-11,5],[-11,4],[-11,3],[-11,2],[-11,1],[-11,0],[-11,-1],[-11,-2],[-11,-3],[-11,-4],[-11,-5],[-11,-6],[-11,-7],[-11,-8],[-11,-9],[-11,-10],[-11,-11],[-10,-11],[-9,-11],[-8,-11],[-7,-11],[-6,-11],[-5,-11],[-4,-11],[-3,-11],[-2,-11],[-1,-11],[0,-11],[1,-11],[2,-11],[3,-11],[4,-11],[5,-11],[6,-11],[7,-11],[8,-11],[9,-11],[10,-11],[11,-11],[11,-10],[11,-9],[11,-8],[11,-7],[11,-6],[11,-5],[11,-4],[11,-3],[11,-2],[11,-1],[11,0],[11,1],[11,2],[11,3],[11,4],[11,5],[11,6],[11,7],[11,8],[11,9],[11,10],[11,11],[11,12],[10,12],[9,12],[8,12],[7,12],[6,12],[5,12],[4,12],[3,12],[2,12],[1,12],[0,12],[-1,12],[-2,12],[-3,12],[-4,12],[-5,12],[-6,12],[-7,12],[-8,12],[-9,12],[-10,12],[-11,12],[-12,12],[-12,11],[-12,10],[-12,9],[-12,8],[-12,7],[-12,6],[-12,5],[-12,4],[-12,3],[-12,2],[-12,1],[-12,0],[-12,-1],[-12,-2],[-12,-3],[-12,-4],[-12,-5],[-12,-6],[-12,-7],[-12,-8],[-12,-9],[-12,-10],[-12,-11],[-12,-12],[-11,-12],[-10,-12],[-9,-12],[-8,-12],[-7,-12],[-6,-12],[-5,-12],[-4,-12],[-3,-12],[-2,-12],[-1,-12],[0,-12],[1,-12],[2,-12],[3,-12],[4,-12],[5,-12],[6,-12],[7,-12],[8,-12],[9,-12],[10,-12],[11,-12],[12,-12],[12,-11],[12,-10],[12,-9],[12,-8],[12,-7],[12,-6],[12,-5],[12,-4],[12,-3],[12,-2],[12,-1],[12,0],[12,1],[12,2],[12,3],[12,4],[12,5],[12,6],[12,7],[12,8],[12,9],[12,10],[12,11],[12,12],[12,13],[11,13],[10,13],[9,13],[8,13],[7,13],[6,13],[5,13],[4,13],[3,13],[2,13],[1,13],[0,13],[-1,13],[-2,13],[-3,13],[-4,13],[-5,13],[-6,13],[-7,13],[-8,13],[-9,13],[-10,13],[-11,13],[-12,13],[-13,13],[-13,12],[-13,11],[-13,10],[-13,9],[-13,8],[-13,7],[-13,6],[-13,5],[-13,4],[-13,3],[-13,2],[-13,1],[-13,0],[-13,-1],[-13,-2],[-13,-3],[-13,-4],[-13,-5],[-13,-6],[-13,-7],[-13,-8],[-13,-9],[-13,-10],[-13,-11],[-13,-12],[-13,-13],[-12,-13],[-11,-13],[-10,-13],[-9,-13],[-8,-13],[-7,-13],[-6,-13],[-5,-13],[-4,-13],[-3,-13],[-2,-13],[-1,-13],[0,-13],[1,-13],[2,-13],[3,-13],[4,-13],[5,-13],[6,-13],[7,-13],[8,-13],[9,-13],[10,-13],[11,-13],[12,-13],[13,-13],[13,-12],[13,-11],[13,-10],[13,-9],[13,-8],[13,-7],[13,-6],[13,-5],[13,-4],[13,-3],[13,-2],[13,-1],[13,0],[13,1],[13,2],[13,3],[13,4],[13,5],[13,6],[13,7],[13,8],[13,9],[13,10],[13,11],[13,12],[13,13],[13,14],[12,14],[11,14],[10,14],[9,14],[8,14],[7,14],[6,14],[5,14],[4,14],[3,14],[2,14],[1,14],[0,14],[-1,14],[-2,14],[-3,14],[-4,14],[-5,14],[-6,14],[-7,14],[-8,14],[-9,14],[-10,14],[-11,14],[-12,14],[-13,14],[-14,14],[-14,13],[-14,12],[-14,11],[-14,10],[-14,9],[-14,8],[-14,7],[-14,6],[-14,5],[-14,4],[-14,3],[-14,2],[-14,1],[-14,0],[-14,-1],[-14,-2],[-14,-3],[-14,-4],[-14,-5],[-14,-6],[-14,-7],[-14,-8],[-14,-9],[-14,-10],[-14,-11],[-14,-12],[-14,-13],[-14,-14],[-13,-14],[-12,-14],[-11,-14],[-10,-14],[-9,-14],[-8,-14],[-7,-14],[-6,-14],[-5,-14],[-4,-14],[-3,-14],[-2,-14],[-1,-14],[0,-14],[1,-14],[2,-14],[3,-14],[4,-14],[5,-14],[6,-14],[7,-14],[8,-14],[9,-14],[10,-14],[11,-14],[12,-14],[13,-14],[14,-14],[14,-13],[14,-12],[14,-11],[14,-10],[14,-9],[14,-8],[14,-7],[14,-6],[14,-5],[14,-4],[14,-3],[14,-2],[14,-1],[14,0],[14,1],[14,2],[14,3],[14,4],[14,5],[14,6],[14,7],[14,8],[14,9],[14,10],[14,11],[14,12],[14,13],[14,14],[14,15],[13,15],[12,15],[11,15],[10,15],[9,15],[8,15],[7,15],[6,15],[5,15],[4,15],[3,15],[2,15],[1,15],[0,15],[-1,15],[-2,15],[-3,15],[-4,15],[-5,15],[-6,15],[-7,15],[-8,15],[-9,15],[-10,15],[-11,15],[-12,15],[-13,15],[-14,15],[-15,15],[-15,14],[-15,13],[-15,12],[-15,11],[-15,10],[-15,9],[-15,8],[-15,7],[-15,6],[-15,5],[-15,4],[-15,3],[-15,2],[-15,1],[-15,0],[-15,-1],[-15,-2],[-15,-3],[-15,-4],[-15,-5],[-15,-6],[-15,-7],[-15,-8],[-15,-9],[-15,-10],[-15,-11],[-15,-12],[-15,-13],[-15,-14],[-15,-15],[-14,-15],[-13,-15],[-12,-15],[-11,-15],[-10,-15],[-9,-15],[-8,-15],[-7,-15],[-6,-15],[-5,-15],[-4,-15],[-3,-15],[-2,-15],[-1,-15],[0,-15],[1,-15],[2,-15],[3,-15],[4,-15],[5,-15],[6,-15],[7,-15],[8,-15],[9,-15],[10,-15],[11,-15],[12,-15],[13,-15],[14,-15],[15,-15],[15,-14],[15,-13],[15,-12],[15,-11],[15,-10],[15,-9],[15,-8],[15,-7],[15,-6],[15,-5],[15,-4],[15,-3],[15,-2],[15,-1],[15,0],[15,1],[15,2],[15,3],[15,4],[15,5],[15,6],[15,7],[15,8],[15,9],[15,10],[15,11],[15,12],[15,13],[15,14],[15,15],[15,16],[14,16],[13,16],[12,16],[11,16],[10,16],[9,16],[8,16],[7,16],[6,16],[5,16],[4,16],[3,16],[2,16],[1,16],[0,16],[-1,16],[-2,16],[-3,16],[-4,16],[-5,16],[-6,16],[-7,16],[-8,16],[-9,16],[-10,16],[-11,16],[-12,16],[-13,16],[-14,16],[-15,16],[-16,16],[-16,15],[-16,14],[-16,13],[-16,12],[-16,11],[-16,10],[-16,9],[-16,8],[-16,7],[-16,6],[-16,5],[-16,4],[-16,3],[-16,2],[-16,1],[-16,0],[-16,-1],[-16,-2],[-16,-3],[-16,-4],[-16,-5],[-16,-6],[-16,-7],[-16,-8],[-16,-9],[-16,-10],[-16,-11],[-16,-12],[-16,-13],[-16,-14],[-16,-15],[-16,-16],[-15,-16],[-14,-16],[-13,-16],[-12,-16],[-11,-16],[-10,-16],[-9,-16],[-8,-16],[-7,-16],[-6,-16],[-5,-16],[-4,-16],[-3,-16],[-2,-16],[-1,-16],[0,-16],[1,-16],[2,-16],[3,-16],[4,-16],[5,-16],[6,-16],[7,-16],[8,-16],[9,-16],[10,-16],[11,-16],[12,-16],[13,-16],[14,-16],[15,-16],[16,-16],[16,-15],[16,-14],[16,-13],[16,-12],[16,-11],[16,-10],[16,-9],[16,-8],[16,-7],[16,-6],[16,-5],[16,-4],[16,-3],[16,-2],[16,-1],[16,0],[16,1],[16,2],[16,3],[16,4],[16,5],[16,6],[16,7],[16,8],[16,9],[16,10],[16,11],[16,12],[16,13],[16,14],[16,15],[16,16],[16,17],[15,17],[14,17],[13,17],[12,17],[11,17],[10,17],[9,17],[8,17],[7,17],[6,17],[5,17],[4,17],[3,17],[2,17],[1,17],[0,17],[-1,17],[-2,17],[-3,17],[-4,17],[-5,17],[-6,17],[-7,17],[-8,17],[-9,17],[-10,17],[-11,17],[-12,17],[-13,17],[-14,17],[-15,17],[-16,17],[-17,17],[-17,16],[-17,15],[-17,14],[-17,13],[-17,12],[-17,11],[-17,10],[-17,9],[-17,8],[-17,7],[-17,6],[-17,5],[-17,4],[-17,3],[-17,2],[-17,1],[-17,0],[-17,-1],[-17,-2],[-17,-3],[-17,-4],[-17,-5],[-17,-6],[-17,-7],[-17,-8],[-17,-9],[-17,-10],[-17,-11],[-17,-12],[-17,-13],[-17,-14],[-17,-15],[-17,-16],[-17,-17],[-16,-17],[-15,-17],[-14,-17],[-13,-17],[-12,-17],[-11,-17],[-10,-17],[-9,-17],[-8,-17],[-7,-17],[-6,-17],[-5,-17],[-4,-17],[-3,-17],[-2,-17],[-1,-17],[0,-17],[1,-17],[2,-17],[3,-17],[4,-17],[5,-17],[6,-17],[7,-17],[8,-17],[9,-17],[10,-17],[11,-17],[12,-17],[13,-17],[14,-17],[15,-17],[16,-17],[17,-17],[17,-16],[17,-15],[17,-14],[17,-13],[17,-12],[17,-11],[17,-10],[17,-9],[17,-8],[17,-7],[17,-6],[17,-5],[17,-4],[17,-3],[17,-2],[17,-1],[17,0],[17,1],[17,2],[17,3],[17,4],[17,5],[17,6],[17,7],[17,8],[17,9],[17,10],[17,11],[17,12],[17,13],[17,14],[17,15],[17,16],[17,17],
        //     [17,18],[16,18],[15,18],[14,18],[13,18],[12,18],[11,18],[10,18],[9,18],[8,18],[7,18],[6,18],[5,18],[4,18],[3,18],[2,18],[1,18],[0,18],[-1,18],[-2,18],[-3,18],[-4,18],[-5,18],[-6,18],[-7,18],[-8,18],[-9,18],[-10,18],[-11,18],[-12,18],[-13,18],[-14,18],[-15,18],[-16,18],[-17,18],[-18,18],[-18,17],[-18,16],[-18,15],[-18,14],[-18,13],[-18,12],[-18,11],[-18,10],[-18,9],[-18,8],[-18,7],[-18,6],[-18,5],[-18,4],[-18,3],[-18,2],[-18,1],[-18,0],[-18,-1],[-18,-2],[-18,-3],[-18,-4],[-18,-5],[-18,-6],[-18,-7],[-18,-8],[-18,-9],[-18,-10],[-18,-11],[-18,-12],[-18,-13],[-18,-14],[-18,-15],[-18,-16],[-18,-17],[-18,-18],[-17,-18],[-16,-18],[-15,-18],[-14,-18],[-13,-18],[-12,-18],[-11,-18],[-10,-18],[-9,-18],[-8,-18],[-7,-18],[-6,-18],[-5,-18],[-4,-18],[-3,-18],[-2,-18],[-1,-18],[0,-18],[1,-18],[2,-18],[3,-18],[4,-18],[5,-18],[6,-18],[7,-18],[8,-18],[9,-18],[10,-18],[11,-18],[12,-18],[13,-18],[14,-18],[15,-18],[16,-18],[17,-18],[18,-18],[18,-17],[18,-16],[18,-15],[18,-14],[18,-13],[18,-12],[18,-11],[18,-10],[18,-9],[18,-8],[18,-7],[18,-6],[18,-5],[18,-4],[18,-3],[18,-2],[18,-1],[18,0],[18,1],[18,2],[18,3],[18,4],[18,5],[18,6],[18,7],[18,8],[18,9],[18,10],[18,11],[18,12],[18,13],[18,14],[18,15],[18,16],[18,17],[18,18],[18,19],[17,19],[16,19],[15,19],[14,19],[13,19],[12,19],[11,19],[10,19],[9,19],[8,19],[7,19],[6,19],[5,19],[4,19],[3,19],[2,19],[1,19],[0,19],[-1,19],[-2,19],[-3,19],[-4,19],[-5,19],[-6,19],[-7,19],[-8,19],[-9,19],[-10,19],[-11,19],[-12,19],[-13,19],[-14,19],[-15,19],[-16,19],[-17,19],[-18,19],[-19,19],[-19,18],[-19,17],[-19,16],[-19,15],[-19,14],[-19,13],[-19,12],[-19,11],[-19,10],[-19,9],[-19,8],[-19,7],[-19,6],[-19,5],[-19,4],[-19,3],[-19,2],[-19,1],[-19,0],[-19,-1],[-19,-2],[-19,-3],[-19,-4],[-19,-5],[-19,-6],[-19,-7],[-19,-8],[-19,-9],[-19,-10],[-19,-11],[-19,-12],[-19,-13],[-19,-14],[-19,-15],[-19,-16],[-19,-17],[-19,-18],[-19,-19],[-18,-19],[-17,-19],[-16,-19],[-15,-19],[-14,-19],[-13,-19],[-12,-19],[-11,-19],[-10,-19],[-9,-19],[-8,-19],[-7,-19],[-6,-19],[-5,-19],[-4,-19],[-3,-19],[-2,-19],[-1,-19],[0,-19],[1,-19],[2,-19],[3,-19],[4,-19],[5,-19],[6,-19],[7,-19],[8,-19],[9,-19],[10,-19],[11,-19],[12,-19],[13,-19],[14,-19],[15,-19],[16,-19],[17,-19],[18,-19],[19,-19],[19,-18],[19,-17],[19,-16],[19,-15],[19,-14],[19,-13],[19,-12],[19,-11],[19,-10],[19,-9],[19,-8],[19,-7],[19,-6],[19,-5],[19,-4],[19,-3],[19,-2],[19,-1],[19,0],[19,1],[19,2],[19,3],[19,4],[19,5],[19,6],[19,7],[19,8],[19,9],[19,10],[19,11],[19,12],[19,13],[19,14],[19,15],[19,16],[19,17],[19,18],[19,19],[19,20],[18,20],[17,20],[16,20],[15,20],[14,20],[13,20],[12,20],[11,20],[10,20],[9,20],[8,20],[7,20],[6,20],[5,20],[4,20],[3,20],[2,20],[1,20],[0,20],[-1,20],[-2,20],[-3,20],[-4,20],[-5,20],[-6,20],[-7,20],[-8,20],[-9,20],[-10,20],[-11,20],[-12,20],[-13,20],[-14,20],[-15,20],[-16,20],[-17,20],[-18,20],[-19,20],[-20,20],[-20,19],[-20,18],[-20,17],[-20,16],[-20,15],[-20,14],[-20,13],[-20,12],[-20,11],[-20,10],[-20,9],[-20,8],[-20,7],[-20,6],[-20,5],[-20,4],[-20,3],[-20,2],[-20,1],[-20,0],[-20,-1],[-20,-2],[-20,-3],[-20,-4],[-20,-5],[-20,-6],[-20,-7],[-20,-8],[-20,-9],[-20,-10],[-20,-11],[-20,-12],[-20,-13],[-20,-14],[-20,-15],[-20,-16],[-20,-17],[-20,-18],[-20,-19],[-20,-20],[-19,-20],[-18,-20],[-17,-20],[-16,-20],[-15,-20],[-14,-20],[-13,-20],[-12,-20],[-11,-20],[-10,-20],[-9,-20],[-8,-20],[-7,-20],[-6,-20],[-5,-20],[-4,-20],[-3,-20],[-2,-20],[-1,-20],[0,-20],[1,-20],[2,-20],[3,-20],[4,-20],[5,-20],[6,-20],[7,-20],[8,-20],[9,-20],[10,-20],[11,-20],[12,-20],[13,-20],[14,-20],[15,-20],[16,-20],[17,-20],[18,-20],[19,-20],[20,-20],[20,-19],[20,-18],[20,-17],[20,-16],[20,-15],[20,-14],[20,-13],[20,-12],[20,-11],[20,-10],[20,-9],[20,-8],[20,-7],[20,-6],[20,-5],[20,-4],[20,-3],[20,-2],[20,-1],[20,0],[20,1],[20,2],[20,3],[20,4],[20,5],[20,6],[20,7],[20,8],[20,9],[20,10],[20,11],[20,12],[20,13],[20,14],[20,15],[20,16],[20,17],[20,18],[20,19],[20,20],[20,21],[19,21],[18,21],[17,21],[16,21],[15,21],[14,21],[13,21],[12,21],[11,21],[10,21],[9,21],[8,21],[7,21],[6,21],[5,21],[4,21],[3,21],[2,21],[1,21],[0,21],[-1,21],[-2,21],[-3,21],[-4,21],[-5,21],[-6,21],[-7,21],[-8,21],[-9,21],[-10,21],[-11,21],[-12,21],[-13,21],[-14,21],[-15,21],[-16,21],[-17,21],[-18,21],[-19,21],[-20,21],[-21,21],[-21,20],[-21,19],[-21,18],[-21,17],[-21,16],[-21,15],[-21,14],[-21,13],[-21,12],[-21,11],[-21,10],[-21,9],[-21,8],[-21,7],[-21,6],[-21,5],[-21,4],[-21,3],[-21,2],[-21,1],[-21,0],[-21,-1],[-21,-2],[-21,-3],[-21,-4],[-21,-5],[-21,-6],[-21,-7],[-21,-8],[-21,-9],[-21,-10],[-21,-11],[-21,-12],[-21,-13],[-21,-14],[-21,-15],[-21,-16],[-21,-17],[-21,-18],[-21,-19],[-21,-20],[-21,-21],[-20,-21],[-19,-21],[-18,-21],[-17,-21],[-16,-21],[-15,-21],[-14,-21],[-13,-21],[-12,-21],[-11,-21],[-10,-21],[-9,-21],[-8,-21],[-7,-21],[-6,-21],[-5,-21],[-4,-21],[-3,-21],[-2,-21],[-1,-21],[0,-21],[1,-21],[2,-21],[3,-21],[4,-21],[5,-21],[6,-21],[7,-21],[8,-21],[9,-21],[10,-21],[11,-21],[12,-21],[13,-21],[14,-21],[15,-21],[16,-21],[17,-21],[18,-21],[19,-21],[20,-21],[21,-21],[21,-20],[21,-19],[21,-18],[21,-17],[21,-16],[21,-15],[21,-14],[21,-13],[21,-12],[21,-11],[21,-10],[21,-9],[21,-8],[21,-7],[21,-6],[21,-5],[21,-4],[21,-3],[21,-2],[21,-1],[21,0],[21,1],[21,2],[21,3],[21,4],[21,5],[21,6],[21,7],[21,8],[21,9],[21,10],[21,11],[21,12],[21,13],[21,14],[21,15],[21,16],[21,17],[21,18],[21,19],[21,20],[21,21],[21,22],[20,22],[19,22],[18,22],[17,22],[16,22],[15,22],[14,22],[13,22],[12,22],[11,22],[10,22],[9,22],[8,22],[7,22],[6,22],[5,22],[4,22],[3,22],[2,22],[1,22],[0,22],[-1,22],[-2,22],[-3,22],[-4,22],[-5,22],[-6,22],[-7,22],[-8,22],[-9,22],[-10,22],[-11,22],[-12,22],[-13,22],[-14,22],[-15,22],[-16,22],[-17,22],[-18,22],[-19,22],[-20,22],[-21,22],[-22,22],[-22,21],[-22,20],[-22,19],[-22,18],[-22,17],[-22,16],[-22,15],[-22,14],[-22,13],[-22,12],[-22,11],[-22,10],[-22,9],[-22,8],[-22,7],[-22,6],[-22,5],[-22,4],[-22,3],[-22,2],[-22,1],[-22,0],[-22,-1],[-22,-2],[-22,-3],[-22,-4],[-22,-5],[-22,-6],[-22,-7],[-22,-8],[-22,-9],[-22,-10],[-22,-11],[-22,-12],[-22,-13],[-22,-14],[-22,-15],[-22,-16],[-22,-17],[-22,-18],[-22,-19],[-22,-20],[-22,-21],[-22,-22],[-21,-22],[-20,-22],[-19,-22],[-18,-22],[-17,-22],[-16,-22],[-15,-22],[-14,-22],[-13,-22],[-12,-22],[-11,-22],[-10,-22],[-9,-22],[-8,-22],[-7,-22],[-6,-22],[-5,-22],[-4,-22],[-3,-22],[-2,-22],[-1,-22],[0,-22],[1,-22],[2,-22],[3,-22],[4,-22],[5,-22],[6,-22],[7,-22],[8,-22],[9,-22],[10,-22],[11,-22],[12,-22],[13,-22],[14,-22],[15,-22],[16,-22],[17,-22],[18,-22],[19,-22],[20,-22],[21,-22],[22,-22],[22,-21],[22,-20],[22,-19],[22,-18],[22,-17],[22,-16],[22,-15],[22,-14],[22,-13],[22,-12],[22,-11],[22,-10],[22,-9],[22,-8],[22,-7],[22,-6],[22,-5],[22,-4],[22,-3],[22,-2],[22,-1],[22,0],[22,1],[22,2],[22,3],[22,4],[22,5],[22,6],[22,7],[22,8],[22,9],[22,10],[22,11],[22,12],[22,13],[22,14],[22,15],[22,16],[22,17],[22,18],[22,19],[22,20],[22,21],[22,22],[22,23],[21,23],[20,23],[19,23],[18,23],[17,23],[16,23],[15,23],[14,23],[13,23],[12,23],[11,23],[10,23],[9,23],[8,23],[7,23],[6,23],[5,23],[4,23],[3,23],[2,23],[1,23],[0,23],[-1,23],[-2,23],[-3,23],[-4,23],[-5,23],[-6,23],[-7,23],[-8,23],[-9,23],[-10,23],[-11,23],[-12,23],[-13,23],[-14,23],[-15,23],[-16,23],[-17,23],[-18,23],[-19,23],[-20,23],[-21,23],[-22,23],[-23,23],[-23,22],[-23,21],[-23,20],[-23,19],[-23,18],[-23,17],[-23,16],[-23,15],[-23,14],[-23,13],[-23,12],[-23,11],[-23,10],[-23,9],[-23,8],[-23,7],[-23,6],[-23,5],[-23,4],[-23,3],[-23,2],[-23,1],[-23,0],[-23,-1],[-23,-2],[-23,-3],[-23,-4],[-23,-5],[-23,-6],[-23,-7],[-23,-8],[-23,-9],[-23,-10],[-23,-11],[-23,-12],[-23,-13],[-23,-14],[-23,-15],[-23,-16],[-23,-17],[-23,-18],[-23,-19],[-23,-20],[-23,-21],[-23,-22],[-23,-23],[-22,-23],[-21,-23],[-20,-23],[-19,-23],[-18,-23],[-17,-23],[-16,-23],[-15,-23],[-14,-23],[-13,-23],[-12,-23],[-11,-23],[-10,-23],[-9,-23],[-8,-23],[-7,-23],[-6,-23],[-5,-23],[-4,-23],[-3,-23],[-2,-23],[-1,-23],[0,-23],[1,-23],[2,-23],[3,-23],[4,-23],[5,-23],[6,-23],[7,-23],[8,-23],[9,-23],[10,-23],[11,-23],[12,-23],[13,-23],[14,-23],[15,-23],[16,-23],[17,-23],[18,-23],[19,-23],[20,-23],[21,-23],[22,-23],
        //     [23,-23],[23,-22],[23,-21],[23,-20],[23,-19],[23,-18],[23,-17],[23,-16],[23,-15],[23,-14],[23,-13],[23,-12],[23,-11],[23,-10],[23,-9],[23,-8],[23,-7],[23,-6],[23,-5],[23,-4],[23,-3],[23,-2],[23,-1],[23,0],[23,1],[23,2],[23,3],[23,4],[23,5],[23,6],[23,7],[23,8],[23,9],[23,10],[23,11],[23,12],[23,13],[23,14],[23,15],[23,16],[23,17],[23,18],[23,19],[23,20],[23,21],[23,22],[23,23],[23,24],[22,24],[21,24],[20,24],[19,24],[18,24],[17,24],[16,24],[15,24],[14,24],[13,24],[12,24],[11,24],[10,24],[9,24],[8,24],[7,24],[6,24],[5,24],[4,24],[3,24],[2,24],[1,24],[0,24],[-1,24],[-2,24],[-3,24],[-4,24],[-5,24],[-6,24],[-7,24],[-8,24],[-9,24],[-10,24],[-11,24],[-12,24],[-13,24],[-14,24],[-15,24],[-16,24],[-17,24],[-18,24],[-19,24],[-20,24],[-21,24],[-22,24],[-23,24],[-24,24],[-24,23],[-24,22],[-24,21],[-24,20],[-24,19],[-24,18],[-24,17],[-24,16],[-24,15],[-24,14],[-24,13],[-24,12],[-24,11],[-24,10],[-24,9],[-24,8],[-24,7],[-24,6],[-24,5],[-24,4],[-24,3],[-24,2],[-24,1],[-24,0],[-24,-1],[-24,-2],[-24,-3],[-24,-4],[-24,-5],[-24,-6],[-24,-7],[-24,-8],[-24,-9],[-24,-10],[-24,-11],[-24,-12],[-24,-13],[-24,-14],[-24,-15],[-24,-16],[-24,-17],[-24,-18],[-24,-19],[-24,-20],[-24,-21],[-24,-22],[-24,-23],[-24,-24],[-23,-24],[-22,-24],[-21,-24],[-20,-24],[-19,-24],[-18,-24],[-17,-24],[-16,-24],[-15,-24],[-14,-24],[-13,-24],[-12,-24],[-11,-24],[-10,-24],[-9,-24],[-8,-24],[-7,-24],[-6,-24],[-5,-24],[-4,-24],[-3,-24],[-2,-24],[-1,-24],[0,-24],[1,-24],[2,-24],[3,-24],[4,-24],[5,-24],[6,-24],[7,-24],[8,-24],[9,-24],[10,-24],[11,-24],[12,-24],[13,-24],[14,-24],[15,-24],[16,-24],[17,-24],[18,-24],[19,-24],[20,-24],[21,-24],[22,-24],[23,-24],[24,-24],[24,-23],[24,-22],[24,-21],[24,-20],[24,-19],[24,-18],[24,-17],[24,-16],[24,-15],[24,-14],[24,-13],[24,-12],[24,-11],[24,-10],[24,-9],[24,-8],[24,-7],[24,-6],[24,-5],[24,-4],[24,-3],[24,-2],[24,-1],[24,0],[24,1],[24,2],[24,3],[24,4],[24,5],[24,6],[24,7],[24,8],[24,9],[24,10],[24,11],[24,12],[24,13],[24,14],[24,15],[24,16],[24,17],[24,18],[24,19],[24,20],[24,21],[24,22],[24,23],[24,24],[24,25],[23,25],[22,25],[21,25],[20,25],[19,25],[18,25],[17,25],[16,25],[15,25],[14,25],[13,25],[12,25],[11,25],[10,25],[9,25],[8,25],[7,25],[6,25],[5,25],[4,25],[3,25],[2,25],[1,25],[0,25],[-1,25],[-2,25],[-3,25],[-4,25],[-5,25],[-6,25],[-7,25],[-8,25],[-9,25],[-10,25],[-11,25],[-12,25],[-13,25],[-14,25],[-15,25],[-16,25],[-17,25],[-18,25],[-19,25],[-20,25],[-21,25],[-22,25],[-23,25],[-24,25],[-25,25],[-25,24],[-25,23],[-25,22],[-25,21],[-25,20],[-25,19],[-25,18],[-25,17],[-25,16],[-25,15],[-25,14],[-25,13],[-25,12],[-25,11],[-25,10],[-25,9],[-25,8],[-25,7],[-25,6],[-25,5],[-25,4],[-25,3],[-25,2],[-25,1],[-25,0],[-25,-1],[-25,-2],[-25,-3],[-25,-4],[-25,-5],[-25,-6],[-25,-7],[-25,-8],[-25,-9],[-25,-10],[-25,-11],[-25,-12],[-25,-13],[-25,-14],[-25,-15],[-25,-16],[-25,-17],[-25,-18],[-25,-19],[-25,-20],[-25,-21],[-25,-22],[-25,-23],[-25,-24],[-25,-25],[-24,-25],[-23,-25],[-22,-25],[-21,-25],[-20,-25],[-19,-25],[-18,-25],[-17,-25],[-16,-25],[-15,-25],[-14,-25],[-13,-25],[-12,-25],[-11,-25],[-10,-25],[-9,-25],[-8,-25],[-7,-25],[-6,-25],[-5,-25],[-4,-25],[-3,-25],[-2,-25],[-1,-25],[0,-25],[1,-25],[2,-25],[3,-25],[4,-25],[5,-25],[6,-25],[7,-25],[8,-25],[9,-25],[10,-25],[11,-25],[12,-25],[13,-25],[14,-25],[15,-25],[16,-25],[17,-25],[18,-25],[19,-25],[20,-25],[21,-25],[22,-25],[23,-25],[24,-25],[25,-25],[25,-24],[25,-23],[25,-22],[25,-21],[25,-20],[25,-19],[25,-18],[25,-17],[25,-16],[25,-15],[25,-14],[25,-13],[25,-12],[25,-11],[25,-10],[25,-9],[25,-8],[25,-7],[25,-6],[25,-5],[25,-4],[25,-3],[25,-2],[25,-1],[25,0],[25,1],[25,2],[25,3],[25,4],[25,5],[25,6],[25,7],[25,8],[25,9],[25,10],[25,11],[25,12],[25,13],[25,14],[25,15],[25,16],[25,17],[25,18],[25,19],[25,20],[25,21],[25,22],[25,23],[25,24],[25,25],[25,26],[24,26],[23,26],[22,26],[21,26],[20,26],[19,26],[18,26],[17,26],[16,26],[15,26],[14,26],[13,26],[12,26],[11,26],[10,26],[9,26],[8,26],[7,26],[6,26],[5,26],[4,26],[3,26],[2,26],[1,26],[0,26],[-1,26],[-2,26],[-3,26],[-4,26],[-5,26],[-6,26],[-7,26],[-8,26],[-9,26],[-10,26],[-11,26],[-12,26],[-13,26],[-14,26],[-15,26],[-16,26],[-17,26],[-18,26],[-19,26],[-20,26],[-21,26],[-22,26],[-23,26],[-24,26],[-25,26],[-26,26],[-26,25],[-26,24],[-26,23],[-26,22],[-26,21],[-26,20],[-26,19],[-26,18],[-26,17],[-26,16],[-26,15],[-26,14],[-26,13],[-26,12],[-26,11],[-26,10],[-26,9],[-26,8],[-26,7],[-26,6],[-26,5],[-26,4],[-26,3],[-26,2],[-26,1],[-26,0],[-26,-1],[-26,-2],[-26,-3],[-26,-4],[-26,-5],[-26,-6],[-26,-7],[-26,-8],[-26,-9],[-26,-10],[-26,-11],[-26,-12],[-26,-13],[-26,-14],[-26,-15],[-26,-16],[-26,-17],[-26,-18],[-26,-19],[-26,-20],[-26,-21],[-26,-22],[-26,-23],[-26,-24],[-26,-25],[-26,-26],[-25,-26],[-24,-26],[-23,-26],[-22,-26],[-21,-26],[-20,-26],[-19,-26],[-18,-26],[-17,-26],[-16,-26],[-15,-26],[-14,-26],[-13,-26],[-12,-26],[-11,-26],[-10,-26],[-9,-26],[-8,-26],[-7,-26],[-6,-26],[-5,-26],[-4,-26],[-3,-26],[-2,-26],[-1,-26],[0,-26],[1,-26],[2,-26],[3,-26],[4,-26],[5,-26],[6,-26],[7,-26],[8,-26],[9,-26],[10,-26],[11,-26],[12,-26],[13,-26],[14,-26],[15,-26],[16,-26],[17,-26],[18,-26],[19,-26],[20,-26],[21,-26],[22,-26],[23,-26],[24,-26],[25,-26],[26,-26],[26,-25],[26,-24],[26,-23],[26,-22],[26,-21],[26,-20],[26,-19],[26,-18],[26,-17],[26,-16],[26,-15],[26,-14],[26,-13],[26,-12],[26,-11],[26,-10],[26,-9],[26,-8],[26,-7],[26,-6],[26,-5],[26,-4],[26,-3],[26,-2],[26,-1],[26,0],[26,1],[26,2],[26,3],[26,4],[26,5],[26,6],[26,7],[26,8],[26,9],[26,10],[26,11],[26,12],[26,13],[26,14],[26,15],[26,16],[26,17],[26,18],[26,19],[26,20],[26,21],[26,22],[26,23],[26,24],[26,25],[26,26],[26,27],[25,27],[24,27],[23,27],[22,27],[21,27],[20,27],[19,27],[18,27],[17,27],[16,27],[15,27],[14,27],[13,27],[12,27],[11,27],[10,27],[9,27],[8,27],[7,27],[6,27],[5,27],[4,27],[3,27],[2,27],[1,27],[0,27],[-1,27],[-2,27],[-3,27],[-4,27],[-5,27],[-6,27],[-7,27],[-8,27],[-9,27],[-10,27],[-11,27],[-12,27],[-13,27],[-14,27],[-15,27],[-16,27],[-17,27],[-18,27],[-19,27],[-20,27],[-21,27],[-22,27],[-23,27],[-24,27],[-25,27],[-26,27],[-27,27],[-27,26],[-27,25],[-27,24],[-27,23],[-27,22],[-27,21],[-27,20],[-27,19],[-27,18],[-27,17],[-27,16],[-27,15],[-27,14],[-27,13],[-27,12],[-27,11],[-27,10],[-27,9],[-27,8],[-27,7],[-27,6],[-27,5],[-27,4],[-27,3],[-27,2],[-27,1],[-27,0],[-27,-1],[-27,-2],[-27,-3],[-27,-4],[-27,-5],[-27,-6],[-27,-7],[-27,-8],[-27,-9],[-27,-10],[-27,-11],[-27,-12],[-27,-13],[-27,-14],[-27,-15],[-27,-16],[-27,-17],[-27,-18],[-27,-19],[-27,-20],[-27,-21],[-27,-22],[-27,-23],[-27,-24],[-27,-25],[-27,-26],[-27,-27],[-26,-27],[-25,-27],[-24,-27],[-23,-27],[-22,-27],[-21,-27],[-20,-27],[-19,-27],[-18,-27],[-17,-27],[-16,-27],[-15,-27],[-14,-27],[-13,-27],[-12,-27],[-11,-27],[-10,-27],[-9,-27],[-8,-27],[-7,-27],[-6,-27],[-5,-27],[-4,-27],[-3,-27],[-2,-27],[-1,-27],[0,-27],[1,-27],[2,-27],[3,-27],[4,-27],[5,-27],[6,-27],[7,-27],[8,-27],[9,-27],[10,-27],[11,-27],[12,-27],[13,-27],[14,-27],[15,-27],[16,-27],[17,-27],[18,-27],[19,-27],[20,-27],[21,-27],[22,-27],[23,-27],[24,-27],[25,-27],[26,-27],[27,-27],[27,-26],[27,-25],[27,-24],[27,-23],[27,-22],[27,-21],[27,-20],[27,-19],[27,-18],[27,-17],[27,-16],[27,-15],[27,-14],[27,-13],[27,-12],[27,-11],[27,-10],[27,-9],[27,-8],[27,-7],[27,-6],[27,-5],[27,-4],[27,-3],[27,-2],[27,-1],[27,0],[27,1],[27,2],[27,3],[27,4],[27,5],[27,6],[27,7],[27,8],[27,9],[27,10],[27,11],[27,12],[27,13],[27,14],[27,15],[27,16],[27,17],[27,18],[27,19],[27,20],[27,21],[27,22],[27,23],[27,24],[27,25],[27,26],[27,27],[27,28],[26,28],[25,28],[24,28],[23,28],[22,28],[21,28],[20,28],[19,28],[18,28],[17,28],[16,28],[15,28],[14,28],[13,28],[12,28],[11,28],[10,28],[9,28],[8,28],[7,28],[6,28],[5,28],[4,28],[3,28],[2,28],[1,28],[0,28],[-1,28],[-2,28],[-3,28],[-4,28],[-5,28],[-6,28],[-7,28],[-8,28],[-9,28],[-10,28],[-11,28],[-12,28],[-13,28],[-14,28],[-15,28],[-16,28],[-17,28],[-18,28],[-19,28],[-20,28],[-21,28],[-22,28],[-23,28],[-24,28],[-25,28],[-26,28],[-27,28],[-28,28],[-28,27],[-28,26],[-28,25],[-28,24],[-28,23],[-28,22],[-28,21],[-28,20],[-28,19],[-28,18],[-28,17],[-28,16],[-28,15],[-28,14],[-28,13],[-28,12],[-28,11],[-28,10],[-28,9],[-28,8],[-28,7],[-28,6],[-28,5],[-28,4],[-28,3],[-28,2],[-28,1],[-28,0],[-28,-1],[-28,-2],[-28,-3],[-28,-4],[-28,-5],[-28,-6],[-28,-7],[-28,-8],[-28,-9],[-28,-10],[-28,-11],[-28,-12],[-28,-13],[-28,-14],[-28,-15],[-28,-16],[-28,-17],[-28,-18],[-28,-19],[-28,-20],[-28,-21],[-28,-22],[-28,-23],[-28,-24],[-28,-25],[-28,-26],[-28,-27],[-28,-28],[-27,-28],[-26,-28],[-25,-28],[-24,-28],[-23,-28],[-22,-28],[-21,-28],[-20,-28],[-19,-28],[-18,-28],[-17,-28],[-16,-28],[-15,-28],[-14,-28],[-13,-28],[-12,-28],[-11,-28],[-10,-28],[-9,-28],[-8,-28],[-7,-28],[-6,-28],[-5,-28],[-4,-28],[-3,-28],[-2,-28],[-1,-28],[0,-28],[1,-28],[2,-28],[3,-28],[4,-28],[5,-28],[6,-28],[7,-28],[8,-28],[9,-28],[10,-28],[11,-28],[12,-28],[13,-28],[14,-28],[15,-28],[16,-28],[17,-28],[18,-28],[19,-28],[20,-28],[21,-28],[22,-28],[23,-28],[24,-28],[25,-28],[26,-28],[27,-28],[28,-28],[28,-27],[28,-26],[28,-25],[28,-24],[28,-23],[28,-22],[28,-21],[28,-20],[28,-19],[28,-18],[28,-17],[28,-16],[28,-15],[28,-14],[28,-13],[28,-12],[28,-11],[28,-10],[28,-9],[28,-8],[28,-7],[28,-6],[28,-5],[28,-4],[28,-3],[28,-2],[28,-1],[28,0],[28,1],[28,2],[28,3],[28,4],[28,5],[28,6],[28,7],[28,8],[28,9],[28,10],[28,11],[28,12],[28,13],[28,14],[28,15],[28,16],[28,17],[28,18],[28,19],[28,20],[28,21],[28,22],[28,23],[28,24],[28,25],[28,26],[28,27],[28,28],[28,29],[27,29],[26,29],[25,29],[24,29],[23,29],[22,29],[21,29],[20,29],[19,29],[18,29],[17,29],[16,29],[15,29],[14,29],[13,29],[12,29],[11,29],[10,29],[9,29],[8,29],[7,29],[6,29],[5,29],[4,29],[3,29],[2,29],[1,29],[0,29],[-1,29],[-2,29],[-3,29],[-4,29],[-5,29],[-6,29],[-7,29],[-8,29],[-9,29],[-10,29],[-11,29],[-12,29],[-13,29],[-14,29],[-15,29],[-16,29],[-17,29],[-18,29],[-19,29],[-20,29],[-21,29],[-22,29],[-23,29],[-24,29],[-25,29],[-26,29],[-27,29],[-28,29],
        //     [-29,29],[-29,28],[-29,27],[-29,26],[-29,25],[-29,24],[-29,23],[-29,22],[-29,21],[-29,20],[-29,19],[-29,18],[-29,17],[-29,16],[-29,15],[-29,14],[-29,13],[-29,12],[-29,11],[-29,10],[-29,9],[-29,8],[-29,7],[-29,6],[-29,5],[-29,4],[-29,3],[-29,2],[-29,1],[-29,0],[-29,-1],[-29,-2],[-29,-3],[-29,-4],[-29,-5],[-29,-6],[-29,-7],[-29,-8],[-29,-9],[-29,-10],[-29,-11],[-29,-12],[-29,-13],[-29,-14],[-29,-15],[-29,-16],[-29,-17],[-29,-18],[-29,-19],[-29,-20],[-29,-21],[-29,-22],[-29,-23],[-29,-24],[-29,-25],[-29,-26],[-29,-27],[-29,-28],[-29,-29],[-28,-29],[-27,-29],[-26,-29],[-25,-29],[-24,-29],[-23,-29],[-22,-29],[-21,-29],[-20,-29],[-19,-29],[-18,-29],[-17,-29],[-16,-29],[-15,-29],[-14,-29],[-13,-29],[-12,-29],[-11,-29],[-10,-29],[-9,-29],[-8,-29],[-7,-29],[-6,-29],[-5,-29],[-4,-29],[-3,-29],[-2,-29],[-1,-29],[0,-29],[1,-29],[2,-29],[3,-29],[4,-29],[5,-29],[6,-29],[7,-29],[8,-29],[9,-29],[10,-29],[11,-29],[12,-29],[13,-29],[14,-29],[15,-29],[16,-29],[17,-29],[18,-29],[19,-29],[20,-29],[21,-29],[22,-29],[23,-29],[24,-29],[25,-29],[26,-29],[27,-29],[28,-29],[29,-29],[29,-28],[29,-27],[29,-26],[29,-25],[29,-24],[29,-23],[29,-22],[29,-21],[29,-20],[29,-19],[29,-18],[29,-17],[29,-16],[29,-15],[29,-14],[29,-13],[29,-12],[29,-11],[29,-10],[29,-9],[29,-8],[29,-7],[29,-6],[29,-5],[29,-4],[29,-3],[29,-2],[29,-1],[29,0],[29,1],[29,2],[29,3],[29,4],[29,5],[29,6],[29,7],[29,8],[29,9],[29,10],[29,11],[29,12],[29,13],[29,14],[29,15],[29,16],[29,17],[29,18],[29,19],[29,20],[29,21],[29,22],[29,23],[29,24],[29,25],[29,26],[29,27],[29,28],[29,29]
        // ];

        // sn_len:number;


        constructor(variables?: {[key: string]: IVariable;}){
            super(variables);
            let batch:SingleRenderer;

            let mapGrap = new MapGrap();
            let sourceSize = SnakeMap.sourceSize;
            mapGrap.source = createBitmapSource("map",sourceSize.x,sourceSize.y,false);
            mapGrap.source.textureData = context3D.getTextureData("map",false,WebGLConst.LINEAR,WebGLConst.LINEAR)
            batch = new SingleRenderer(mapGrap);

            if(ROOT.shadow){
                mapGrap.addFilter(new ShadowFilter(mapGrap))
            }

            batch.depth = true;
            batch.depthMode = WebGLConst.LEQUAL;
            mapGrap.renderer = batch;
            mapGrap.setSca(1, SY , 1);
            mapGrap.z = -0.1;
            this.setRot(RX,0,0);
            // this.z = 0;
            this.addChild(mapGrap);
            this.mapGrap = mapGrap;

            let mapHalo = new Sprite();
            mapHalo.setSca(1, SY, 1);
            mapHalo.renderer = new SuperBatchRenderer(mapHalo);
            this.addChild(mapHalo);
            this.mapHalo = mapHalo;
        }

        getFull(s:string,len:number){
            while(s.length<len){
                s = "0"+s;
            }
            return s;
        }

        init(data:IMapData,sceneWidth:number,sceneHeight:number){
            this.data = data;
            this.gx = -1;
            this.gy = -1;
            let p = `m/${data.id}/`;
            this.perfix = p;
            this.setSize(sceneWidth,sceneHeight);

            if(!data.setting){
                data.setting = new Map2DSetting(data);
            }
        }

        render(camera:Camera,option:IRenderOption) { 
            // let{rtt} = this;
            // let c = context3D;
            // if(!rtt){
            //     this.rtt = rtt = c.createRttTexture(c.getTextureData("maprtt"),c.backBufferWidth,c.backBufferHeight);
            // }

            // c.setRenderToTexture(rtt);

            super.render(camera, option);

            // c.setRenderToBackBuffer();

            // pass_normal_render(rtt);
        }


        setSize(width:number,height:number){
            super.setSize(width,height);
            this.sw = width;
            this.sh = height;
            let{pw,ph}=this.data;
            this.gw = Math.ceil(width / pw) + 1;
            this.gh = Math.ceil(height / ph) + 1;
        }


        setviewRect(x:number,y:number){
            let{data,gx,gy}=this;
            let{pw,ph}=data;

            let dx = Math.floor(x/pw);
            let dy = Math.floor(y/ph);

            if(gx == dx && gy == dy){  
                return;
            }

            this.gx = dx;
            this.gy = dy;

            let{perfix,gw,gh,mapGrap}=this;
            let{graphics,source}=mapGrap;
            let{w,h}=data;

            let frames = source.areas[0].frames;

            graphics.clear();

            let needloads:number[][] = []

            for(let j = 0;j<gh;j++){
                for(let i = 0;i<gw;i++){
                    let x = dx + i;
                    let y = dy + j;

                    if(x < 0 || y < 0 || x * pw >= w || y * ph >= h){
                        continue;
                    }

                    let url = perfix + `${this.getFull(y+"",3)}${this.getFull(x+"",3)}.jpg`;

                    let vo = frames[url];

                    if(vo == undefined){
                        needloads.push([url as any,x,y]);
                    }else{
                        graphics.drawBitmap(x*pw,y*ph,vo);
                    }
                    // console.log(x,y,url);
                }
            }


            for (let i = 0; i < needloads.length; i++) {
                let [url,x,y] = needloads[i];
                let vo = source.setSourceVO(url+"",data.pw,data.ph);
                if(vo){
                    loadRes(RES_PERFIX,url+"",this.maploadCompleteHandler,this,ResType.image);
                    graphics.drawBitmap(x*pw,y*ph,vo);
                }else{
                    console.log(x,y,"no draw");
                }
            }


            // for (let count = 0;count<sn_len;count++){
            //     let [i,j] = snakes[count];

            //     i += dx;
            //     j += dy;

            //     if(i < 0 || j < 0 || i * pw > w || j * ph > h){
            //         continue;
            //     }

            //     let url = perfix + `${this.getFull(j+"",3)}${this.getFull(i+"",3)}.jpg`;
            //     let vo = this.source.setSourceVO(url,data.pw,data.ph);
            //     if(vo){
            //         loadRes(RES_PERFIX,url,this.maploadCompleteHandler,this,ResType.image);
            //         graphics.drawBitmap(i*pw,j*ph,vo);
            //         console.log(i,j,url);
            //     }
            // }
            graphics.end();

        }



        maploadCompleteHandler(event:EventX){
            let{source} = this.mapGrap;
            let vo = source.getSourceVO((event.currentTarget as ImageLoader).url);
            if(vo){
                source.drawimg(event.data,vo.x,vo.y,vo.w,vo.h)
            }
        }
    }

}